# -*- coding: utf-8 -*-
from ip.opdef import *
from mtl.base import OP_FILE


def ld(pid, dst, src, sb_addr=None, ain_addr=None):
    op = TranOp()
    op.op_code = 0
    op.dst_peer_id = pid
    op.dst_addr = dst
    op.src_addr = src
    op.dst_sb_addr = (-1) if sb_addr is None else (sb_addr)
    op.dst_ain_addr = (-1) if ain_addr is None else (ain_addr)
    op.len_limit = 1
    op.dst_stride = 1
    op.dst_clear = False
    op.src_stride = 1
    OP_FILE['tops'].append(op)


def ld_v(pid, dst, count, src, sb_addr=None, ain_addr=None, dst_stride=None, src_stride=None):
    op = TranOp()
    op.op_code = 0
    op.dst_peer_id = pid
    op.dst_addr = dst
    op.len_limit = count
    op.src_addr = src
    op.dst_sb_addr = (-1) if sb_addr is None else (sb_addr)
    op.dst_ain_addr = (-1) if ain_addr is None else (ain_addr)
    op.dst_stride = (1) if dst_stride is None else (dst_stride)
    op.src_stride = (1) if src_stride is None else (src_stride)
    op.dst_clear = False
    OP_FILE['tops'].append(op)


def clr(pid, dst, sb=None, ain=None):
    op = TranOp()
    op.op_code = 1
    op.dst_peer_id = pid
    op.dst_addr = dst
    op.dst_sb_addr = (-1) if sb is None else (sb)
    op.dst_ain_addr = (-1) if ain is None else (ain)
    op.len_limit = 1
    op.dst_stride = 1
    op.dst_clear = True
    op.src_addr = -1
    op.src_stride = 1
    OP_FILE['tops'].append(op)


def clr_v(pid, dst, count, sb=None, ain=None, dst_stride=None):
    op = TranOp()
    op.op_code = 1
    op.dst_peer_id = pid
    op.dst_addr = dst
    op.len_limit = count
    op.dst_sb_addr = (-1) if sb is None else (sb)
    op.dst_ain_addr = (-1) if ain is None else (ain)
    op.dst_stride = (1) if dst_stride is None else (dst_stride)
    op.dst_clear = True
    op.src_addr = -1
    op.src_stride = 1
    OP_FILE['tops'].append(op)

